package cn.ming.springbootreadwriteseparationdemo.commons;

import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * @ClassName RoutingDataSource
 * @Description 数据源路由类
 * @Author zhuming
 * @Date 2021-08-01 22:06
 * @Version 1.0.0
 */
@Slf4j
public class RoutingDataSource extends AbstractRoutingDataSource {
    /**
     * 检索当前目标数据源
     * @return
     */
    @Override
    protected Object determineCurrentLookupKey() {
        log.info(">>>线程：{},数据源：{}<<<", Thread.currentThread().getName(),DataSourceContextHolder.getDbContextLocal());
        return DataSourceContextHolder.getDbContextLocal();
    }
}
